// 引入UI组件
import Count from "../../components/Count";
// 引入connect用于连接UI和redux
import {connect} from 'react-redux'

import {createDecrementAction, createIncrementAction, creatIncrementActionAsync} from "../../redux/count_action";

// react-redux在调用该函数是，已经将store的state传入了. 该函数用于将state映射为props传入UI组件
const mapStateToProps = (state) => {
  return {num: state}
}

// 该函数用于将dispatch行为以K,V形式(对象)映射为props传递给UI组件
/*const mapDispatchToProps = (dispatch) => {
  return {
    add: data => dispatch(createIncrementAction(data)),
    minus: data => dispatch(createDecrementAction(data)),
    addAsync: (data, wait) => dispatch(creatIncrementActionAsync(data, wait))
  }
}*/

/*
mapDispathToProps可以简写为一个对象，V为创建action的函数，react-redux会接收到action对象并自动dispatch
 */
const mapDispatchToProps = {
  add: createIncrementAction,
  minus: createDecrementAction,
  addAsync:creatIncrementActionAsync

}

// 导出容器组件
export default connect(mapStateToProps, mapDispatchToProps)(Count);
